<?php

/**
 * 报表
 */
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Service\ApiService;
use Illuminate\Pagination\LengthAwarePaginator;
use Excel;
class ReportController extends Controller
{
    public $v = 'admin.report.';
	public $paginate = 15;

	/**
	 * 礼物记录
	 * @param Request $request
	 * @return type
	 */
	public function index(Request $request, ApiService $apiService){		
		$gift = [];
		$guild = $request->query('guild');
		$keyword = $request->query('keyword');
		$time_value = $request->query('time_value');
		//$perPage = 3;
        //当前页数 默认1
        $page = $request->page ?: 1;
        //计算每页分页的初始位置
        $offset = ($page * $this->paginate) - $this->paginate;
		$rest = $apiService->getGift(['guild' => $guild, 'keyword' => $keyword, 'time_value' => $time_value]);
		if($rest['count'] != 0) {
			$gift = new LengthAwarePaginator(array_slice($rest['list'], $offset, $this->paginate, true), $rest['count'], $this->paginate,
				$page, ['path' => $request->url(), 'query' => $request->query()]);
		}
		$guildlist = $apiService->getGuildShow();
        return view($this->v . 'index', compact('gift', 'guildlist', 'guild', 'keyword', 'time_value'));
	}
	/**
	 * 短视频记录
	 * @param Request $request
	 * @return type
	 */
	public function video(Request $request){		
        return view($this->v . 'index');
	}
	/**
	 * 邮票记录
	 * @param Request $request
	 * @return type
	 */
	public function stamp(Request $request, ApiService $apiService){		
        $stamp = [];
		$guild = $request->query('guild');
		$keyword = $request->query('keyword');
		$time_value = $request->query('time_value');
		//$perPage = 3;
        //当前页数 默认1
        $page = $request->page ?: 1;
        //计算每页分页的初始位置
        $offset = ($page * $this->paginate) - $this->paginate;
		$rest = $apiService->getStamp(['guild' => $guild, 'keyword' => $keyword, 'time_value' => $time_value]);
		if($rest['count'] != 0) {
			$stamp = new LengthAwarePaginator(array_slice($rest['list'], $offset, $this->paginate, true), $rest['count'], $this->paginate,
				$page, ['path' => $request->url(), 'query' => $request->query()]);
		}
		$guildlist = $apiService->getGuildShow();
        return view($this->v . 'stamp', compact('guildlist', 'guild', 'keyword', 'time_value', 'stamp'));
	}
	/**
	 * 通话记录
	 * @param Request $request
	 * @return type
	 */
	public function call(Request $request, ApiService $apiService){
		/*$cellData = [
            ['学号','姓名','成绩'],
			['10001','大幅度','99'],
			['10002','BBBBB','92'],
			['10003','CCCCC','95'],
			['10004','DDDDD','89'],
			['10005','EEEEE','96'],
        ];
        Excel::create("学生成绩",function ($excel) use ($cellData){
            $excel->sheet('score',function ($sheet) use ($cellData) {
                $sheet->rows($cellData);
				ob_end_clean();
            });
        })->export('csv');*/
		$call = [];
		$guild = $request->query('guild');
		$keyword = $request->query('keyword');
		$time_value = $request->query('time_value');
		//$perPage = 3;
        //当前页数 默认1
        $page = $request->page ?: 1;
        //计算每页分页的初始位置
        $offset = ($page * $this->paginate) - $this->paginate;
		$rest = $apiService->getCall(['guild' => $guild, 'keyword' => $keyword, 'time_value' => $time_value]);
		if($rest['count'] != 0) {
			$call = new LengthAwarePaginator(array_slice($rest['list'], $offset, $this->paginate, true), $rest['count'], $this->paginate,
				$page, ['path' => $request->url(), 'query' => $request->query()]);
		}
		$guildlist = $apiService->getGuildShow();
        return view($this->v . 'call', compact('guildlist', 'guild', 'keyword', 'time_value', 'call'));
	}
}
